<?php
/**
 * @file $HeadURL: libraryfocuscontroller.php $
 * @author $Author: yuebin (yuebin@haibao.com) $
 * @date $Date: 2015-07-07 11:39:40 $
 * @brief 
 */
namespace haibao\cms\business\control\pc\channel\library;

use haibao\frame\data\query\Condition;
use \haibao\cms\model\filter\imagecollective\ImageCollective as ImageCollectiveFilter;
use \haibao\cms\model\filter\imagecollective\ImageCollectivePro as ImageCollectiveProFilter;
use \haibao\cms\model\filter\imagecollective\ImageCollectiveTag as ImageCollectiveTagFilter;
use \haibao\cms\model\filter\ImageLibrary as ImageLibraryFilter;


class LibraryFocusController extends \haibao\cms\business\control\pc\channel\ChannelController{
	
	private $dataList = array();
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	public function displayTemplateHtml(){
		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		
		$this->getImageCollList($controlData['manual']);
		$wwwHost = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HAIBAO_URL);
		$hotWord = array(
		   0=>array(
		       'wordTitle'=> '服饰潮流',
		       'wordUrl'=> $wwwHost.'/search/index.html?name='.rawurlencode('服饰潮流').'&type=3&orderType=3&isHighLight=0',
		   ),
		   1=>array(
		       'wordTitle'=> '明星街拍',
		       'wordUrl'=> $wwwHost.'/search/index.html?name='.rawurlencode('明星街拍').'&type=3&orderType=3&isHighLight=0',
		   ),
		   2=>array(
		       'wordTitle'=> '美容护肤',
		       'wordUrl'=> $wwwHost.'/search/index.html?name='.rawurlencode('美容护肤').'&type=3&orderType=3&isHighLight=0',
		   ),
		   3=>array(
		       'wordTitle'=> '鞋靴',
		       'wordUrl'=> $wwwHost.'/search/index.html?name='.rawurlencode('鞋靴').'&type=3&orderType=3&isHighLight=0',
		   ),
		   4=>array(
		       'wordTitle'=> '街拍·Beauty',
		       'wordUrl'=> $wwwHost.'/search/index.html?name='.rawurlencode('街拍·Beauty').'&type=3&orderType=3&isHighLight=0',
		   ),
		   5=>array(
		       'wordTitle'=> '明星子女',
		       'wordUrl'=> $wwwHost.'/search/index.html?name='.rawurlencode('明星子女').'&type=3&orderType=3&isHighLight=0',
		   ),
		);
// 		$controlInfo = \haibao\cms\business\PageControl::getOnLinePageControlDataByControlId(339);
// 		foreach($controlInfo as $data){
// 		    if($data->type == 'library'){
// 		    	array_push($hotWord,$data);
// 		    }
// 		}

        $this->assign('hotWord', $hotWord);		
		$this->assign('dataList', json_decode(json_encode($this->dataList)));
		$this->assign('picUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_PIC));
		$path = $this->generateHtmlPath(__CLASS__);
		$this->generateHtml($path,$content);
		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
	
	/**
	 * 获取图集数据
	 */
	private function getImageCollList($dataCondition){//limit = 8 
		
		$imageCollFilter = new ImageCollectiveFilter();
		$imageCollFilter->select(array(
			ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,
			ImageCollectiveFilter::CONDITION_FIELD_NAME_TITLE,
			ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,
		));
		
		$imageCollProFilter = new ImageCollectiveProFilter();
		$imageCollProFilter->select(array(
			ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_ID,
		));
		
		$imageLibraryFilter = new ImageLibraryFilter();
		$imageLibraryFilter->select(array(
			ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
				
		));
		
		$imageCollTagFilter = new ImageCollectiveTagFilter();
		$imageCollTagFilter->select(array(
		    ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID
		));
		
		$imageCollFilter->order(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,false);
		$imageCollFilter->limit(0,$dataCondition['limit']);
		$imageCollFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,$dataCondition['level']);
		$imageCollFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_LESSEQUAL,$dataCondition['biglevel']);
		$imageCollFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::PUBLISH_MOBILE_YES);
		
		$imageCollProFilter->where(ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_IMAGE_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectivePro::IMAGE_TYPE_FOUR);
		$imageCollFilter->innerJoin($imageCollProFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PRO,false);
		$imageCollFilter->innerJoin($imageLibraryFilter,$imageCollProFilter,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_FILENAME,false);
		
		$imageCollTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,1);
		$imageCollFilter->innerJoin($imageCollTagFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		
		$imageCollList = \haibao\cms\business\imagecollective\ImageCollective::getImageCollectiveByFilter($imageCollFilter);
		
		if($imageCollList){
		    $topTagIds = self::getTopTags();
			foreach($imageCollList as $list){
				$temp = array();
				$temp['Id'] = $list->Id;
				$temp['Title'] = $list->Title;
				$temp['PublishTime'] = $this->formatDate($list->PublishTime->format('Y-m-d H:i:s'));
				$temp['SiteType'] = self::DATA_TYPE_IMAGE_SET;
				$temp['ProImage'] = isset($list->ImageCollectivePro->FileName)?$list->ImageCollectivePro->FileName->Filename:'';
				$topTagId = isset($topTagIds[$list->ImageCollectiveTag->ParentId]) ? $list->ImageCollectiveTag->ParentId : 6;
				$temp['Channel'] = self::getArticleUrl($list->Id,$topTagId,self::DATA_TYPE_IMAGE_SET);
				array_push($this->dataList,$temp);
			}
		}
	}
	
}